﻿''' <summary>
''' 锐剑财务系统 会计期间表
''' 对应表-会计期间表
''' </summary>
Public Class RjClsWorkPeriodDbAccess
    Inherits ClsBaseDbAccess

    Public Sub New(ByVal s As String)
        MyBase.New(s, TABLE_NAME_RJ_WORKPERIOD)
    End Sub

    Public Sub New(ByVal s As String, ByVal n As String)
        MyBase.New(s, n)
    End Sub

    Public Function GetCurWorkPeriod() As RjClsWorkPeriod


        Dim tmpCls As RjClsWorkPeriod = Nothing

        Try
            Dim tmpDb As ClsDbAccessMdb = GetConnection()

            'Dim tmpParas(0) As OleDb.OleDbParameter
            Dim tmpSql As String = "Select * from  [" & Me.AppTableName & "] "
            tmpSql &= " where not [结账] "
            tmpSql &= " Order by [月份] "

            '打开数据库
            tmpDb.DbOpen()

            '执行
            Dim tmpList As List(Of RjClsWorkPeriod) = New List(Of RjClsWorkPeriod)()
            tmpList = TryCast(ConvertRecordToClass(tmpDb.ExecuteSqlReturnDataSet(tmpSql, New OleDb.OleDbParameter() {})), List(Of RjClsWorkPeriod))
            If tmpList.Count > 0 Then
                tmpCls = tmpList.Item(0)
            End If

            '关闭数据库
            tmpDb.DbClose()

        Catch ex As OleDb.OleDbException

            mErrorCreater = "ClsTAccountDbAccess - GetOpenWorkPeriod"
            mErrorMessage = ex.Message
            mErrorNumber = ex.ErrorCode

        End Try

        Return tmpCls

    End Function

    ''' <summary>
    ''' 取锐剑财务系统账套的启用期间
    ''' </summary>
    ''' <returns></returns>
    Public Function GetOpenWorkPeriod() As RjClsWorkPeriod

        Dim tmpCls As RjClsWorkPeriod = Nothing

        Try
            Dim tmpDb As ClsDbAccessMdb = GetConnection()

            'Dim tmpParas(0) As OleDb.OleDbParameter
            Dim tmpSql As String = "Select * from  [" & Me.AppTableName & "] "
            tmpSql &= " Order by [月份] "

            '打开数据库
            tmpDb.DbOpen()

            '执行
            Dim tmpList As List(Of RjClsWorkPeriod) = New List(Of RjClsWorkPeriod)()
            tmpList = TryCast(ConvertRecordToClass(tmpDb.ExecuteSqlReturnDataSet(tmpSql, New OleDb.OleDbParameter() {})), List(Of RjClsWorkPeriod))
            If tmpList.Count > 0 Then
                tmpCls = tmpList.Item(0)
            End If

            '关闭数据库
            tmpDb.DbClose()

        Catch ex As OleDb.OleDbException

            mErrorCreater = "ClsTAccountDbAccess - GetOpenWorkPeriod"
            mErrorMessage = ex.Message
            mErrorNumber = ex.ErrorCode

        End Try

        Return tmpCls

    End Function

    Public Overrides Function ConvertRecordToClass(reader As OleDb.OleDbDataReader) As Object

        If reader Is Nothing Then
            Return Nothing
        End If

        Try

            Dim tmpList As List(Of RjClsWorkPeriod) = New List(Of RjClsWorkPeriod)
            Dim tmpCls As RjClsWorkPeriod

            While reader.Read()

                tmpCls = New RjClsWorkPeriod()

                With tmpCls

                    .PeriodId = reader.GetInt32(0)
                    .Year = reader.GetString(1)
                    .Month = reader.GetInt32(2)
                    .VoucherCount = reader.GetInt32(3)
                    .Posted = reader.GetBoolean(4)
                    .Settled = reader.GetBoolean(5)

                End With

                tmpList.Add(tmpCls)

            End While

            Return tmpList

        Catch ex As Exception

            mErrorNumber = -1001
            mErrorMessage = ex.Message
            mErrorCreater = "ClsTVoucherGroupDbAccess - ConvertRecordToClass"

            Return Nothing
        End Try

    End Function

End Class
